package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.entity.hz.SFCTA;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.vo.ProcessVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-03-18
 */
public interface SfctaMapper extends BaseMapper<SFCTA> {

    /**
     * 根据 工单单别 工单单号 加工顺序 来获取对应的 工单工艺详细信息
     * @param TA001
     * @param TA002
     * @param TA003
     * @return
     */
    @DS("demo")
    @Select("select * from SFCTA where TA001 = #{TA001} and TA002 = #{TA002} and TA003 = #{TA003}")
    SFCTA getByTA001WithTA002WithTA003(String TA001, String TA002, String TA003);

    @DS("demo")
    @Select("SELECT A.TA001,A.TA002,A.TA003,A.TA004, MW002 gyname,A.TA024 FROM SFCTA A LEFT JOIN CMSMW ON MW001 = A.TA004 LEFT JOIN MOCTA B ON A.TA001 = B.TA001 AND A.TA002 = B.TA002 WHERE B.TA013 = 'Y' AND B.TA011 != 'Y' AND B.TA011 != 'y'")
    List<ProcessVo> getProcess();

    @DS("demo")
    @Select("SELECT DISTINCT TA001,TA002,TA003,TA004,MW002 gyname,CONVERT(VARCHAR(MAX), TA024) TA024 FROM SFCTA LEFT JOIN CMSMW ON MW001 = TA004")
    List<ProcessVo> getProcessList();

    @DS("demo")
    @Select("SELECT TOP 1 * FROM SFCTA WHERE TA001 = #{te006} AND TA002 = #{te007} AND TA003 < #{te008} ORDER BY TA003 DESC")
    SFCTA getLastDishNum(String te006, String te007, String te008);

    @DS("erp3_help")
    @Select("SELECT * FROM SFCTA")
    List<SFCTA> all();

    List<String> getSfctaKeyList();
}
